<?php

	namespace application\model;
		require_once ("RecipeDALmodel.php");
		require_once ("DALInfoModel.php");

		class RecipeCollectionModel
		{
				
			private $mysqli;
			private $recipeDAL;
			private $recipes;
			private $recipe;
			private $recipeCollection = array();

			//tar emot adress till databas som skicaks vidare till ny RecipeDAL klass
			//Som i sin tur återvänder med uthämtade recept i form av array

			public function __construct(\mysqli $dbConnection)
			{
	
				$this->mysqli = new \application\model\DALInfoModel();
				$this->recipeDALmodel = new \application\model\RecipeDALmodel($this->mysqli->getDALInfo());
					
				$this->recipeDAL = new RecipeDALmodel($dbConnection);
				$this->recipes = $this->recipeDAL->getAllRecipes();
			}

			public function getRecipeCollection()
			{
				foreach ($this->recipes as $key => $value)
				{
					$this->recipeCollection[] = $value;
				}
				return $this->recipeCollection;
			}

			public function getSingleRecipe($recipeId)
			{
				$this->recipe = $this->recipeDAL->getOneRecipe($recipeId);
				return $this->recipe;
			}

			public function getLatestAddedRecipe()
			{
				$this->recipe = $this->recipeDAL->getLatestRecipe();
				return $this->recipe;
			}

			public function deleteRecipeFromCollection($recipeId)
			{
				$this->recipe = $this->recipeDAL->deleteRecipe($recipeId);
				return true;

				//TODO try catch??
			}

			public function addRecipeToRecipeCollection($recipe)
			{
				$this->recipeDALmodel->saveRecipe($recipe);
				return;
			}

			public function updateRecipeInRecipeCollection($recipe)
			{
				$this->recipeDALmodel->updateRecipe($recipe);
				return;
			}
			
			public function getRecipeListByType($recipeTypeId)
			{
				$this->recipeCollection = $this->recipeDAL->getRecipeListByType("RecipeTypeID", $recipeTypeId);
				return $this->recipeCollection;
			}
			
			public function getRecipeListByAuthor($recipeAuthorId)
			{
				$this->recipeCollection = $this->recipeDAL->getRecipeListByType("AuthorID", $recipeAuthorId);
				return $this->recipeCollection;
			}
			
			public function getRecipeListByText($textString)
			{
				$this->recipeCollection = $this->recipeDAL->getRecipeListByText("RecipeName", $textString);
				return $this->recipeCollection;
			}
			public function getRecipeListByTag($tagString)
			{
				$this->recipeCollection = $this->recipeDAL->getRecipeListByText("RecipeTags", $tagString);
				return $this->recipeCollection;
			}
			
			
			

		}
